<?php /* COMPANIES $Id: companies.class.php,v 1.9.12.1 2006/07/25 20:24:13 merlinyoda Exp $ */
/**
 *	@package dotProject
 *	@subpackage modules
 *	@version $Revision: 1.9.12.1 $
*/

require_once( $AppUI->getSystemClass ('dp' ) );
define('PUBLIC_PAGE', 'm=public&a=access_denied');
/**
 *	Companies Class
 *	@todo Move the 'address' fields to a generic table
 */
class CCompany extends CDpObject {
/** @var int Primary Key */
	var $company_id = NULL;
/** @var string */
	var $company_name = NULL;

// these next fields should be ported to a generic address book
	var $company_phone1 = NULL;
	var $company_phone2 = NULL;
	var $company_fax = NULL;
	var $company_address1 = NULL;
	var $company_address2 = NULL;
	var $company_city = NULL;
	var $company_state = NULL;
	var $company_zip = NULL;
	var $company_email = NULL;
	// trangdt add
	/*
	 * ALTER TABLE `companies` ADD `company_parent` INT( 11 ) NULL DEFAULT '0';
	 */
	 /*sql
	  * ALTER TABLE `companies` ADD `comopany_code` VARCHAR( 20 ) NOT NULL ,
							ADD `comopany_status` INT( 11 ) NOT NULL ,
							ADD `comopany_type2` INT( 11 ) NOT NULL ,
							ADD `comopany_class` INT( 11 ) NOT NULL ,
							ADD `comopany_division` INT( 11 ) ,
							ADD `comopany_costcenter` INT( 11 ),
							ADD `comopany_classification` INT( 11 ) ,
							ADD `comopany_resource` INT( 11 ),
							ADD `comopany_markup` DOUBLE default '0' COMMENT 'ty le % lai',
							ADD `comopany_ledge1` varchar(255) NOT NULL,
							ADD `comopany_ledge2` varchar(255) NOT NULL;
		 ALTER TABLE `companies` ADD `company_exact_code` VARCHAR( 255);
		 ALTER TABLE `companies` ADD `company_vat_code` VARCHAR( 255);
	  */
	var $company_code = NULL;
	var $company_status = NULL;
	var $company_type2 = NULL;
	var $company_classification = NULL;
	var $company_division = NULL;
	var $company_costcenter = NULL;
	var $company_resource = NULL;
	var $company_markup = NULL;
	var $company_vat_code = NULL;
	var $company_ledge1 = NULL;
	var $company_ledge2 = NULL;
	var $company_parent = 0;
	var $company_exact_code;
	// trangdt end

/** @var string */
	var $company_primary_url = NULL;
/** @var int */
	var $company_owner = NULL;
/** @var string */
	var $company_description = NULL;
/** @var int */
	var $company_type = null;

	var $company_custom = null;

	function CCompany() {
		$joins = array(
			array( 'label' => 'Projects', 'name' => 'projects', 'idfield' => 'project_id', 'joinfield' => 'project_company' ),
			array( 'label' => 'Users', 'name' => 'users', 'idfield' => 'user_id', 'joinfield' => 'user_company' ),
			array( 'label' => 'Quotations', 'name' => 'quotations', 'idfield' => 'quote_id', 'joinfield' => 'quote_customer' ),
			array( 'label' => 'Tasks', 'name' => 'tasks', 'idfield' => 'task_id', 'joinfield' => 'task_customer' ),
			array( 'label' => 'Items', 'name' => 'items', 'idfield' => 'item_id', 'joinfield' => 'item_customer' ),
			array( 'label' => 'Contacts', 'name' => 'contacts', 'idfield' => 'contact_id', 'joinfield' => 'contact_company' )
		);
		$this->CDpObject( 'companies', 'company_id', 'company_code', $joins, 'companies' );
	}

// overload check
	function check() {
		if ($this->company_id === NULL) {
			return 'company id is NULL';
		}
		$this->company_id = intval( $this->company_id );

		return NULL; // object is ok
	}

	function getParentName(){
		$parent_name='';
		if($company_parent != 0){
			$q->addTable('companies');
			$q->addQuery('company_name');
			$q->addWhere('company_id='.$this->company_parent);
			$parent_name = $q->loadResult();
		}
		return $parent_name;
	}

}
?>
